<template>
    <el-card shadow="never">
        <el-tabs type="card" v-model="type" @tab-change="tabChange">
            <el-tab-pane name="Driver" label="司机">
            </el-tab-pane>
            <el-tab-pane name="Seller" label="销售">
            </el-tab-pane>
        </el-tabs>
        <yun-table
                v-if="columns"
                :columns="columns"
                :common-search="false"
                ref="fasttable"
                toolbar="refresh,add,edit,del"
                :auth="{
                    add:{:$auth->check('app\\admin\\controller\\delivery\\channel\\Staff','add')},
                    edit:{:$auth->check('app\\admin\\controller\\delivery\\channel\\Staff','edit')},
                    del:{:$auth->check('app\\admin\\controller\\delivery\\channel\\Staff','del')},
                    multi:{:$auth->check('app\\admin\\controller\\delivery\\channel\\Staff','multi')},
                }"
                :extend="extend">
        </yun-table>
    </el-card>
</template>
<script>
    import table from "@components/Table.js";
    export default{
        components:{
            'YunTable':table,
        },
        data:{
            extend:{},
            type:'',
            columns:'',
            row:Yunqi.data.row
        },
        onLoad:function(options){
            this.type=options.type || 'Driver';
            this.init();
        },
        methods: {
            init:function (){
                this.extend={
                    index_url: 'delivery/channel-staff/index?type='+this.type,
                    add_url: 'delivery/channel-staff/add?type='+this.type,
                    edit_url: 'delivery/channel-staff/edit?type='+this.type,
                    del_url: 'delivery/channel-staff/del?type='+this.type,
                    multi_url: 'delivery/channel-staff/multi?type='+this.type,
                };
                let type='';
                if(this.type=='Driver'){
                    type='司机';
                }
                if(this.type=='Seller'){
                    type='销售';
                }
                this.columns=[
                    {checkbox: true},
                    {field:"realname",title:type+"姓名"},
                    {field:"mobile",title:"手机号"},
                    {
                        field:"user_id",
                        title:"绑定用户",
                        operate:false,
                        formatter:function (data,row){
                            if(!row.user){
                                return;
                            }
                            let tag=Yunqi.formatter.tag;
                            tag.value=row.user.nickname;
                            return tag;
                        }
                    },
                    {field:"status",title:"状态",formatter:Yunqi.formatter.switch,operate:"select",searchList:{normal:"正常",hidden:"隐藏"}},
                    {
                        field: 'operate',
                        title: __('操作'),
                        width:130,
                        action:{
                            edit:true,
                            del:true,
                        },
                    }
                ];
            },
            tabChange:function(e){
                this.type=e;
                this.columns='';
                Vue.nextTick(()=>{
                    this.init();
                });
            }
        }
    }
</script>
<style>

</style>
